﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;

namespace MemberServerBLL
{
    public class WebConfigTool
    {
        public static void SetValue(string key, string strValue, string FileName)
        {
            string XPath = "/appSettings/add[@key='?']";
            XmlDocument membershipConfig = new XmlDocument();

            membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
            XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
            if (addKey == null)
            {
                throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
            }
            addKey.Attributes["value"].InnerText = strValue;
            membershipConfig.Save((HttpContext.Current.Server.MapPath(FileName)));
        }

        public static string GetValue(string key, string FileName)
        {
            string XPath = "/appSettings/add[@key='?']";
            XmlDocument membershipConfig = new XmlDocument();

            membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
            XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
            if (addKey == null)
            {
                throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
            }
            return addKey.Attributes["value"].InnerText;

        }
    }
}
